<?php
    /**
     * Created by PhpStorm.
     * 版权所有: 2019~2022 [ hhygyl ]
     * Date: 2019/7/23-17:09
     * Link: http://luckyadmin.luckyhhy.cn
     * FileName: Model.php
     * Keys: ctrl+alt+L/ctrl+s(代码格式化) ctrl+J(代码提示) ctrl+R(替换)ALT+INSERT(生成代码(如GET,SET方法,构造函数等) , 光标在类中才生效)
     * CTRL+ALT+O (优化导入的类和包 需要配置) SHIFT+F2(高亮错误或警告快速定位错误)
     * CTRL+SHIFT+Z(代码向前) CTRL+SHIFT+/ (块状注释) ctrl+shift+enter(智能完善代码 如if())
     **************************************************************
     *                                                            *
     *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.       *
     *    |                     ______                     |      *
     *    |                  .-"      "-.                  |      *
     *    |                 /            \                 |      *
     *    |     _          |              |          _     |      *
     *    |    ( \         |,  .-.  .-.  ,|         / )    |      *
     *    |     > "=._     | )(__/  \__)( |     _.=" <     |      *
     *    |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |      *
     *    |           "=._"(_     ^^     _)"_.="           |      *
     *    |               "=\__|IIIIII|__/="               |      *
     *    |              _.="| \IIIIII/ |"=._              |      *
     *    |    _     _.="_.="\          /"=._"=._     _    |      *
     *    |   ( \_.="_.="     `--------`     "=._"=._/ )   |      *
     *    |    > _.="                            "=._ <    |      *
     *    |   (_/                                    \_)   |      *
     *    |                                                |      *
     *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
     *                                                            *
     *                    JUST FIND YOUR BUG !                    *
     **************************************************************
     */

    namespace app\admin\controller;


    use think\Exception;

    class Model extends SystemBase
    {
        protected $model;

        protected function _initialize()
        {
            parent::_initialize(); // TODO: Change the autogenerated stub
            $this->model = new \app\admin\model\Model();
        }


        /**
         * @return mixed
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: index
         * @describe:数据展示
         */
        public function index()
        {

            if($this->request->isAjax()) {
                $param = $this->request->param();//接收参数
                /**
                 * 返回获取的分页数据
                 */
                return $this->model->GetModelDataPage($param);
            }

            return $this->fetch();
        }



        /**
         * @return mixed
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: AddModel
         * @describe:添加模型
         */
        public function AddModel()
        {
            if($this->request->isAjax()) {
                $data                   = $this->request->post();
                $data['index_template'] = "index";
                $res = $this->model->addEditData($data);
                if($res['code']==1) {
                    if(isset($data['id'])){
                        $this->AddLogs('编辑模型【'.$data['name'].'】');
                    }else{
                        $this->AddLogs('添加模型【'.$data['name'].'】');
                    }
                    $this->success("提交成功");
                }
                else {
                    $this->error($res['msg']);
                }

            }
            return $this->fetch();
        }



        /**
         * @return mixed
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: EditModel
         * @describe:编辑
         */
        public function EditModel()
        {
            $id   = $this->request->param("id/d");
            $info = $this->model->get($id);
            $this->assign("info", $info);

            return $this->fetch();
        }


        public function delete(){

            if($this->request->isAjax()) {
                $ids = $this->request->post("ids");
                return $this->DeleteData("model",$ids);
            }
        }

    }